class Solution {
    public int romanToInt(String s) {
         int sum = 0;
            s = s.replace("IV","a");
            s = s.replace("IX","b");
            s = s.replace("XL","c");
            s = s.replace("XC","d");
            s = s.replace("CD","e");
            s = s.replace("CM","f");

        for(int j = 0;j < s.length() ; j++){
            if(s.charAt(j) == 'I'){
                sum+= 1;
            }else if(s.charAt(j) == 'V') {
                sum+= 5;
            }else if(s.charAt(j) == 'X') {
                sum+= 10;
            }else if(s.charAt(j) == 'L') {
                sum+= 50;
            }else if(s.charAt(j) == 'C') {
                sum+= 100;
            }else if(s.charAt(j) == 'D') {
                sum+= 500;
            }else if(s.charAt(j) == 'M') {
                sum+= 1000;
            }else{
                switch(s.charAt(j)){
                    case 'a':
                        sum += 4;
                        break;
                    case 'b':
                        sum += 9;
                        break;
                    case 'c':
                        sum += 40;
                        break;
                    case 'd':
                        sum += 90;
                        break;
                    case 'e':
                        sum += 400;
                        break;
                    case 'f':
                        sum += 900;
                        break;
                }
            }
        }
        return sum;
    }
}